package com.xiecong.controller;

import com.xiecong.pojo.Emp;
import com.xiecong.pojo.LoginInfo;
import com.xiecong.pojo.Result;
import com.xiecong.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class LoginController {

    @Autowired
    private EmpService empService;

    @PostMapping("/login")
    public Result login(@RequestBody Emp emp){
        log.info("员工登录:{}",emp);
        // 调用业务层获取响应参数
        LoginInfo loginInfo = empService.login(emp);
        // 判断是否登录成功
        if(loginInfo !=null){
            //不为空即返回成功
            return Result.success(loginInfo);
        }else{
            // 为空即匹配失败
            return Result.error("用户名或密码错误~~");
        }
    }
}
